package main

import "fmt"

func main() {

	db := &Db{}
	defer db.Close()

	defer CloseFile()

	fmt.Println("do something")

}

type Db struct{}

func (db *Db) Close() {
	// Close the file or resource here
	defer fmt.Println("Closing resource")

	fmt.Println("do something before closing resource")
}

func CloseFile() {
	// Close the file or resource here
	defer fmt.Println("Closing file")

	fmt.Println("do something before closing file")
}
